package com.woniuxy.secondhand.controller;


import com.woniuxy.life.core.api.CommonResult;
import com.woniuxy.secondhand.entity.Post;
import com.woniuxy.secondhand.service.PostService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 邮寄地址表 前端控制器
 * </p>
 *
 * @author chaohuijiang
 * @since 2020-09-24
 */
@RestController
@RequestMapping("/secondhand/post")
public class PostController {
  @Resource
  PostService postService;
  //新增地址
  @PostMapping("/insert")
  public CommonResult<Post> insertPost(@RequestBody Post post){
    System.out.println(post);
    boolean re=postService.save(post);
    if (re){
      return CommonResult.success();
    }
    return CommonResult.failed();
  }
  //删除地址
  @DeleteMapping("/delete/{id}")
  public CommonResult<Post> delete(@PathVariable("id") Integer id){
    boolean re=postService.removeById(id);
    if (re){
      return CommonResult.success();
    }
    return CommonResult.failed();
  }
  //修改
//  @PutMapping("/update")
//  public CommonResult<Post> update(){
//
//  }
  //查询
  @GetMapping("/select/{id}")
  public CommonResult<Post> select(@PathVariable("id") Integer id){
    Post post= postService.getById(id);
    return CommonResult.success(post);
  }
}
